package org.twnmayberry.blimpl;

import javax.persistence.EntityManager;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.twnmayberry.bl.MayberryTestUtil;
import org.twnmayberry.jpa.DBUtil;

public class MayberryTestUtilImpl implements MayberryTestUtil {

	private static Log log = LogFactory.getLog(MayberryTestUtilImpl.class);
	
    protected static final String DROP_SCRIPT =
        "ddl/twnmayberryDrop.ddl";
    protected static final String CREATE_SCRIPT =
        "ddl/twnmayberryCreate.ddl";
    protected EntityManager em;

    @Override
    public void setEntityManager(EntityManager em) {
        this.em = em;
    }
    
    protected DBUtil getDBUtil() {
        DBUtil dbUtil = new DBUtil();
        dbUtil.setEntityManager(em);
        dbUtil.setDropPath(DROP_SCRIPT);
        dbUtil.setCreatePath(CREATE_SCRIPT);
        return dbUtil;
    }

    @Override
    public void resetAll() {
	DBUtil dbUtil = getDBUtil();
	try {
		dbUtil.dropAll();
		dbUtil.createAll();
	} catch (Exception e) {
		log.error("Unable to reset DB in DMV Test Util: ", e);
	}
	
}


}
